package cn.huiyunche.admin.tms.controller;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.huiyunche.admin.service.interfaces.DLinesService;
import cn.huiyunche.base.service.model.DLines;
import cn.huiyunche.base.service.vo.PageVo;
import cn.huiyunche.base.service.vo.Result;

import com.alibaba.fastjson.JSON;

/**
 * 线路
 * @author zhj
 * 
 */

@Controller
@RequestMapping("/dlines")
public class DLinesController {
	private static final Logger logger = LoggerFactory.getLogger(DLinesController.class);
	
	@Autowired
	private DLinesService dLinesService = null;
	
	private DLinesService getDLinesService() {
		return this.dLinesService;
	}
	
	/**
	 * 查询线路列表
	 */
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	@ResponseBody
	public Result<Object> list(PageVo page, DLines dlines){
		Result<Object> result = new Result<Object>(true, null, "数据加载成功");
		result.setData(this.getDLinesService().getList(page, dlines));
		return result;
	}
	
	/**
	 * 对线路列表添加操作
	 */
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	@ResponseBody
	public Result<String> add(DLines dlines, BindingResult br) {
		Result<String> result = new Result<String>(true, "线路列表添加成功");
		if (br.hasErrors()) {
			List<ObjectError> list = br.getAllErrors();
			result.setSuccess(false);
			result.setMessage(list.get(0).getDefaultMessage());
			return result;
		}
		return this.getDLinesService().addDLines(dlines);
	}
	
	/**
	 * 对线路列表修改操作
	 */
	@RequestMapping(value = "/modify", method = RequestMethod.POST)
	@ResponseBody
	public Result<Map<String, Object>> modify(DLines dlines){
		logger.info("modify dlines params : {}.", JSON.toJSONString(dlines));
		Result<Map<String, Object>> result = new Result<Map<String, Object>>(true, null, "线路列表修改成功");
		result.setData(this.getDLinesService().modifyDLines(dlines));
		return result;
	}
	
}
